﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Utility
{
	// Token: 0x0200035D RID: 861
	public class Enum<T> where T : struct
	{
		// Token: 0x06001580 RID: 5504 RVA: 0x000923C4 File Offset: 0x000905C4
		public static bool ContainsKey(string key)
		{
			foreach (string b in Enum.GetNames(typeof(T)))
			{
				if (key == b)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x06001581 RID: 5505 RVA: 0x00092408 File Offset: 0x00090608
		public static T Cast(string key, bool isErrorCheck = false)
		{
			if (isErrorCheck && !Enum<T>.ContainsKey(key))
			{
				GlobalData.Debug_LogError("enum转换失败了 : " + key);
				return Enum<T>.Cast(int.MaxValue, false);
			}
			return (T)((object)Enum.Parse(typeof(T), key));
		}

		// Token: 0x06001582 RID: 5506 RVA: 0x00092458 File Offset: 0x00090658
		public static T Cast(int no, bool isErrorCheck = false)
		{
			Type typeFromHandle = typeof(T);
			if (isErrorCheck && !Enum.IsDefined(typeFromHandle, no))
			{
				GlobalData.Debug_LogError("enum转换失败了 : " + no);
				no = int.MaxValue;
			}
			return (T)((object)Enum.ToObject(typeFromHandle, no));
		}

		// Token: 0x06001583 RID: 5507 RVA: 0x000924B0 File Offset: 0x000906B0
		public static int Length()
		{
			return Enum.GetValues(typeof(T)).Length;
		}

		// Token: 0x06001584 RID: 5508 RVA: 0x000924C8 File Offset: 0x000906C8
		public static Enum<T>.EnumerateEnum Enumerate()
		{
			return new Enum<T>.EnumerateEnum();
		}

		// Token: 0x0200035E RID: 862
		public class EnumerateEnum
		{
			// Token: 0x06001586 RID: 5510 RVA: 0x000924D8 File Offset: 0x000906D8
			public IEnumerator<T> GetEnumerator()
			{
				IEnumerator enumerator = Enum.GetValues(typeof(T)).GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						object obj = enumerator.Current;
						T e = (T)((object)obj);
						yield return e;
					}
				}
				finally
				{
					IDisposable disposable;
					if ((disposable = (enumerator as IDisposable)) != null)
					{
						disposable.Dispose();
					}
				}
				yield break;
			}
		}
	}
}
